﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MSAcademic.v2.Infrastructure.Article;
using MSAcademic.v2.Infrastructure.Tag;
using MSAcademic.v2.Infrastructure.User;

namespace MSAcademic.v2.Web.Models
{
    public partial class ArticleViewModel
    {
        public int ArticleId { get; set; }
    }
    public partial class ArticleViewModel
    {
        public IArticle Article
        {
            get
            {
                if (_article == null)
                {
                    _article = new Lazy<IArticle>(() => _articleQueries.GetArticle(ArticleId));
                }
                return _article.Value;
            }
        }
        private Lazy<IArticle> _article;

        public List<ITag> ArticleTags
        {
            get
            {
                if (_articleTags == null)
                {
                    _articleTags = new Lazy<List<ITag>>(() => _tagQueries.GetTagsForArticle(ArticleId).ToList());
                }
                return _articleTags.Value;
            }
        }
        private Lazy<List<ITag>> _articleTags;
        public IUser Author
        {
            get
            {
                if (_author == null)
                {
                    _author = new Lazy<IUser>(() => _userQueries.GetArticleAuthor(ArticleId));
                }
                return _author.Value;
            }
        }
        private Lazy<IUser> _author;
    }
    public partial class ArticleViewModel
    {
        private readonly IArticleQueries _articleQueries ;
        private readonly ITagQueries _tagQueries;
        private readonly IUserQueries _userQueries;
        public ArticleViewModel(IArticleQueries articleQueries,ITagQueries tagQueries,IUserQueries userQueries)
        {
            _tagQueries = tagQueries;
            _articleQueries = articleQueries;
            _userQueries = userQueries;
        }
    }
}